package com.uff.hmstpa.vision.impl.windows;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.uff.hmstpa.model.ScheduleSystemModel;
import com.uff.hmstpa.model.domain.Doctor;
import com.uff.hmstpa.model.domain.Patient;
import com.uff.hmstpa.vision.command.CreateAppointmentCommand;

@SuppressWarnings("serial")
public class CreateAppointmentFrame extends JFrame {

	private JPanel contentPane;
	private JTextField dateTextField;	
	public JComboBox<Doctor> doctorComboBox = new JComboBox<Doctor>();
	public JComboBox<Patient> patientComboBox = new JComboBox<Patient>();

	public CreateAppointmentFrame(ScheduleSystemModel model) {
		
		setTitle("Criar Consulta");
		setAlwaysOnTop(true);
		setBounds(100, 100, 449, 217);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblDoutor = new JLabel("Doutor:");
		lblDoutor.setBounds(19, 11, 37, 14);
		contentPane.add(lblDoutor);
		
		JLabel lblPaciente = new JLabel("Paciente:");
		lblPaciente.setBounds(10, 55, 46, 14);
		contentPane.add(lblPaciente);
		
		doctorComboBox.setBounds(66, 11, 358, 20);
		contentPane.add(doctorComboBox);
		
		patientComboBox.setBounds(66, 52, 358, 20);
		contentPane.add(patientComboBox);
		
		JLabel lblData = new JLabel("Data:");
		lblData.setBounds(29, 100, 27, 14);
		contentPane.add(lblData);
		
		dateTextField = new JTextField();
		dateTextField.setText("dd/mm/aaaa");
		dateTextField.setBounds(66, 97, 133, 20);
		contentPane.add(dateTextField);
		dateTextField.setColumns(10);
		
		JLabel lblHorrio = new JLabel("Horário:");
		lblHorrio.setBounds(222, 100, 46, 14);
		contentPane.add(lblHorrio);
		
		JComboBox<String> timeComboBox = new JComboBox<String>();
		timeComboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"08h - 09h", "09h - 10h", "10h - 11h", "11h - 12h", "14h - 15h", "15h - 16h", "16h - 17h", "17h - 18h"}));
		timeComboBox.setBounds(278, 97, 146, 20);
		contentPane.add(timeComboBox);
		
		JCheckBox chckbxBuscarEmDomiclio = new JCheckBox("Buscar em domicílio");
		chckbxBuscarEmDomiclio.setBounds(66, 148, 139, 23);
		contentPane.add(chckbxBuscarEmDomiclio);
		
		JButton createAppointmentButtom = new JButton(new CreateAppointmentCommand(doctorComboBox, patientComboBox, dateTextField, timeComboBox, chckbxBuscarEmDomiclio));
		createAppointmentButtom.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		createAppointmentButtom.setBounds(335, 128, 89, 43);
		createAppointmentButtom.setText("Agendar");
		contentPane.add(createAppointmentButtom);
		
		for(Doctor doctor : model.getDoctors()) {
			doctorComboBox.addItem(doctor);
		}
		
		for(Patient patient : model.getPatients()) {
			patientComboBox.addItem(patient);
		}
		
		this.setVisible(false);
	}
	
}
